package a.bb.cc;
//package cn.shoukaiseki.reddragon.exceptionadvice;


import lombok.extern.slf4j.Slf4j;
import org.noear.solon.core.AppContext;
import org.noear.solon.core.Plugin;
import org.noear.solon.core.event.AppBeanLoadEndEvent;
import org.noear.solon.core.util.ResourceUtil;

import java.util.Collection;

/** cn.shoukaiseki.reddragon.exceptionadvice.RedDragonExceptionAdvicePluginImpl
 * 全局异常处理建议
 * <br>
 * @author shoukaiseki
 * 主页 https://gitee.com/shoukaiseki/<br>
 * E-mail jiang28555@qq.com<br>
 * @date 2024-05-13 17:15:41<br>
 */
@Slf4j
public class RedDragonExceptionAdvicePluginImpl implements Plugin {

    @Override
    public void start(AppContext context) throws Throwable {

        context.beanBuilderAdd(ExceptionAdvice.class, (clz, bw, anno) -> {
            context.onEvent(AppBeanLoadEndEvent.class,e->{
                System.out.println("ExceptionAdvice2="+clz.getName());
                IExceptionAdvice exceptionAdvice = context.beanMake(clz).raw();
            });
        });
        //类不在插件中,该方法也无法扫到
        //只有在同一个包下才能
//        context.beanScan("a");

        //能扫描到所有模块下a包下的所有类
        Collection<Class<?>> clzs = ResourceUtil.scanClasses(context.getClassLoader(), "a.**");
        clzs.forEach(System.out::println);
    }

}
